<?php
	include("includes/secure.php");
	if ( isset($_GET["ban_code"]) && (int) $_GET["ban_code"] > 0){
		include("includes/config.php");
		include("includes/class/request.class.php");
		
		$myRequest = new MyRequest();
		
		$ban_code = $_GET['ban_code'];		
		$dataBank = $myRequest->getBank($ban_code);
		
		if(isset($_POST['add']) && $_POST['add'] == 1){
			$data->baco_name = trim(mysql_real_escape_string($_POST['baco_name']));
			$data->ban_code = trim(mysql_real_escape_string($_POST['ban_code']));
		
			if ( $baco_code = $myRequest->addContactBank($data) ){
				$bankContactList = $myRequest->bankContactList($_POST['ban_code']);
				$countBankContactList = count ($bankContactList);
				
				$html = '<select name="baco_code" id="baco_code" class="text_grv" onchange="javascript: chargeBankContact(this.value);">';
				$html .= '<option value="" selected="selected" disabled="disabled">select..</option>';
				for ($i = 0; $i < $countBankContactList; $i++){
				if ( $bankContactList[$i]->baco_code == $baco_code )
						$selected = 'selected';
					else
						$selected = '';
					$html .= '<option value="'.$bankContactList[$i]->baco_code.'" '.$selected.'>'.$bankContactList[$i]->baco_name.'</option>';
				}
				$html .= '<option value="-1">New contact bank..</option>';
				$html .= '</select>';			
				echo $html;
				
				echo ("<script> parent.reloadContactsBank('".$html."')</script>");
			}else
				echo "<script> parent.showCoolMessage('It could not be added the contact bank.', 1) </script>";	
		}	
	}
	else
		echo ("<script> window.top.$.fn.fancybox.close() ;</script>");
?>